package com.cheng.example.juc;


public class synchronizedDemo {
    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            try {
                MethodTest.f1();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        Thread.sleep(1000);
        new Thread(() -> {
            try {
                MethodTest1.f1();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}

class MethodTest {

    public static synchronized void f1() throws InterruptedException {
        synchronized (SyTest.anInt) {
            Thread.sleep(2000);
            SyTest.anInt = 2;
            System.out.println("老子执行完毕:" + SyTest.anInt);
        }
    }
}

class MethodTest1 {
    public static synchronized void f1() throws InterruptedException {
//        synchronized (SyTest.anInt) {
            SyTest.anInt = 5;
            System.out.println("闭嘴吧狗日的:" + SyTest.anInt);
//        }
    }
}

class Thread01 extends Thread {
    @Override
    public void run() {

    }
}
